<?php

class TymModel extends NObject
{
	private $table = 'dbo.Tym';
	private $tym_lide = 'dbo.Tym_Lide';
	private $connection;


	public static function initialize()
	{
		dibi::connect(NEnvironment::getConfig('database'));
	}
	
	public function __construct()
	{
		$this->connection = dibi::getConnection();
	}
	//-----------
	//FIND ALL
	//-----------	
	public function findAll()
	{
		return $this->connection->select('*')->from($this->table);
	}
	//-----------
	//FIND BY ID
	//-----------
	public function findById($id)
	{
		return $this->connection->query("SELECT [*] FROM ".$this->table." WHERE id=%i",$id);
		//return $this->connection->select('*')->from($this->table)->where('id=%i',$id);
	}
	//-----------
	//UPDATE
	//-----------
	public function update($id, array $data)
	{
		return $this->connection->update($this->table, $data)->where('id=%i', $id)->execute();
	}
	//-----------
	//INSERT
	//-----------	
	public function insert(array $data)
	{
		return $this->connection->insert($this->table, $data)->execute(dibi::IDENTIFIER);
	}
	//-----------
	//FIND ALL
	//-----------
	public function delete($id)
	{
		return $this->connection->query("DELETE FROM ".$this->table." WHERE id=%i", $id);
		//return $this->connection->delete($this->table)->where('id=%i', $id)->execute();
	}
	
	
	/*  TYM_LIDE  */
	
	
	public function tym_lide_findAll()
	{
		return $this->connection->select('*')->from($this->tym_lide);
	}
	public function tym_lide_findById($id)
	{
		return $this->connection->query("SELECT [*] FROM ".$this->tym_lide." WHERE id=%i",$id);
	}
	public function tym_lide_findByTymId($id)
	{
		return $this->connection->query("SELECT [*] FROM ".$this->tym_lide." WHERE tym_id=%i",$id);
	}
	public function tym_lide_delete($id)
	{
		return $this->connection->query("DELETE FROM ".$this->tym_lide." WHERE id=%i", $id);
	}
	public function tym_lide_update($id, array $data)
	{
		return $this->connection->update($this->tym_lide, $data)->where('id=%i', $id)->execute();
	}
	public function tym_lide_insert(array $data)
	{
		return $this->connection->insert($this->tym_lide, $data)->execute(dibi::IDENTIFIER);
	}


}
